package com.droidexchange.main;

import java.util.ArrayList;
import net.sf.stackwrap4j.entities.Question;
import android.text.Html;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import com.droidexchange.util.StringFormatter;
import com.droidexchange.util.StringFormatter.StringElem;

public class DeQuestionsItem
{
	StringFormatter	strFormatter	= new StringFormatter();
	public Question question;

	public DeQuestionsItem(Question question)
	{
		this.question = question;
	}

	public SpannableStringBuilder sgetText()
	{
		SpannableStringBuilder csAll = new SpannableStringBuilder();
		try
		{
			ArrayList<StringElem> elems = strFormatter.format(question.getBody());
			for (int i = 0; i < elems.size(); i++)
			{
				StringElem elem = elems.get(i);
				if (elem.type == StringFormatter.TYPE_HTML)
				{
					csAll = csAll.append(Html.fromHtml(elem.cs.toString()));
				}
				else if (elem.type == StringFormatter.TYPE_CODE)
				{
					SpannableStringBuilder ssb = new SpannableStringBuilder(elem.cs);
					ssb.setSpan(new ForegroundColorSpan(0xFFFF0000), 0, elem.cs.length(), 0);
					csAll = csAll.append(ssb);
				}
			}
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

		return csAll;
	}

}
